<?php


class jwWidgetGalleryPictures extends sfWidgetForm
{
  /**
   * @param array $options     An array of options
   * @param array $attributes  An array of default HTML attributes
   *
   * @see sfWidgetForm
   */
  protected function configure($options = array(), $attributes = array())
  {
  }

  /**
   * @param  string $name        The element name
   * @param  string $value       The value displayed in this widget
   * @param  array  $attributes  An array of HTML attributes to be merged with the default HTML attributes
   * @param  array  $errors      An array of errors for the field
   *
   * @return string An HTML tag string
   *
   * @see sfWidgetForm
   */
  public function render($name, $value = null, $attributes = array(), $errors = array())
  {
  
    $id = get_id_from_name( $name );
    $content = 
	"
	<link rel='stylesheet' type='text/css' media='screen' href='/jwGalleryPlugin/css/jwGallery.css'>
	<script type='text/javascript' src='/jwGalleryPlugin/js/swfupload.js'></script>
	<script type='text/javascript' src='/jwGalleryPlugin/js/swfupload.queue.js'></script>
	<script type='text/javascript' src='/jwGalleryPlugin/js/swfupload.speed.js'></script>
	<script type='text/javascript' src='/jwGalleryPlugin/js/handlers.js'></script>
    <script type='text/javascript' src='/sfProtoculousPlugin/js/prototype.js'></script>    
    <script type='text/javascript' src='/sfProtoculousPlugin/js/effects.js'></script>    
    <script type='text/javascript' src='/sfProtoculousPlugin/js/dragdrop.js'></script>    
    <script type='text/javascript'>
		var swfu;

		window.onload = function() {
            var ul_cont = jwGallery.DomManipulators.getTableImagesContainer( $('".$id."_status') );        
			var settings = {
				flash_url : '/jwGalleryPlugin/swf/swfupload.swf',
				upload_url: '".url_for( 'jwGalleryAdmin/uploadImage' )."',
				//upload_url: '/backend.php/jwGalleryAdmin/uploadImage',
				post_params: {'".ini_get('session.name')."': '".session_id()."', namespace: '".$name."'},
				file_size_limit : '100 MB',
				file_types : '*.jpg;*.jpeg;*.png',
				file_types_description : 'Images',
				file_upload_limit : 100,
				file_queue_limit : 0,

				debug: false,

				// Button settings
				button_image_url: '/jwGalleryPlugin/images/XPButtonUploadText_61x22.png',
				//button_image_url: '/jwGalleryPlugin/images/image--plus.png',
				button_width: '61',
				button_height: '22',
				button_placeholder_id: '".get_id_from_name( $id )."_spanButtonPlaceHolder',
				button_text: '<span class=\"buttonText\">".__('upload')."</span>',
				button_text_style: '.buttonText { text-align: center; }',
  
				
				moving_average_history_size: 40,
				
				// The event handler functions are defined in handlers.js
				file_queued_handler : Handlers.fileQueued,
				file_dialog_complete_handler: Handlers.fileDialogComplete,
				file_dialog_start_handler: Handlers.fileDialogStart,
				upload_start_handler : Handlers.uploadStart,
				upload_progress_handler : Handlers.uploadProgress,
				upload_success_handler : Handlers.uploadSuccess,
				upload_complete_handler : Handlers.uploadComplete,
				
				custom_settings : {
                  progress : document.getElementById( '".$id."_progress' ),
                  progressData : document.getElementById( '".$id."_progress_data' ),
                  cont : ul_cont
				}
			};
            
            Sortable.create( ul_cont, { overlap: 'horizontal', constraint: '', onChange: jwGallery.EventHandlers.onChange } );

			swfu = new SWFUpload(settings);
	     };
	</script>";
    
    $content .= "<span id='".$id."_spanButtonPlaceHolder'></span><div ID='".$id."_status' class='status' ><div ID='".$id."_upload_progress_cont' class='upload_progress_cont'><div ID='".$id."_progress_data' class='progress_data' ></div><div ID='".$id."_progress' class='progress'></div></div></div><div style='clear:both' ></div>";
  
    return $content;

  }
}
?>